package com.woniuxy.bookmall.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SendEmailRabbitConfig {

    public static final String SEND_EMAIL_EXHCANGE = "send_email_exchange" ;
    public static final String SEND_EMAIL_QUEUE =  "send_email_queue";
    public static final String SEND_EMAIL_ROUTING_KEY = "send_email_routing_key";
    //实例化交换机
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(SEND_EMAIL_EXHCANGE,true,false);
    }
    //实例化队列
    @Bean
    public Queue queue() {
        return new Queue(SEND_EMAIL_QUEUE,true);
    }
    //绑定交换机和队列
    @Bean
     public Binding binding() {
        return BindingBuilder.bind(queue()).to(directExchange()).with(SEND_EMAIL_ROUTING_KEY);
    }
}
